package com.jt.aop;

import com.jt.pojo.User;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Aspect
public class SpringAOP {
    private static Map<Integer,User> map = new HashMap();

    @Around("@annotation(com.jt.anno.A)")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result =null;

                Object[] args = joinPoint.getArgs();
        User u = (User) args[0];
        Integer id = u.getId();
        if(map.containsKey(id)){
            System.out.println("执行缓冲数据"+map.get(id));
            System.out.println(id);
        }else {
            result = joinPoint.proceed();
            map.put(id, u);

        }

        return result;
    }

}
